package com.da.lon.wang.xlg.activity;

import android.app.Dialog;
import android.os.Build;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;

import com.ant.liao.GifView;
import com.ant.liao.GifView.GifImageType;
import com.da.lon.wang.xlg.R;
import com.da.lon.wang.xlg.util.StatusBarDarkModeUtils;

public class BaseActivity extends FragmentActivity {

    private Dialog dialog;
    private View dialogView;
    private GifView dialogGifView;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        // TODO Auto-generated method stub
        super.onCreate(savedInstanceState);
        dialogView = LayoutInflater.from(this).inflate(R.layout.ocoffee_loading_dialog, null);
        dialogGifView = (GifView) dialogView.findViewById(R.id.loading_gif);
        dialogGifView.setGifImage(R.drawable.gif);
        dialogGifView.setGifImageType(GifImageType.COVER);
    }

    protected void showDialog() {
        this.showDialog("");
    }

    public void showDialog(CharSequence title) {

        if (dialog == null) {
            dialog = new Dialog(this, R.style.ocoffee_loading_dialog);
            dialog.setCanceledOnTouchOutside(false);
            dialog.setContentView(dialogView);
        }
        if (dialog != null && !dialog.isShowing()) {
            dialog.show();
        }


    }

    protected void dismissDialog() {

        if (dialog != null && dialog.isShowing()) {
            dialog.dismiss();
        }


    }

    @Override
    public void onDestroy() {
        if (dialog != null && dialog.isShowing()) {
            dialog.dismiss();
        }
        super.onDestroy();
        if (dialog != null && dialog.isShowing()) {
            dialog.dismiss();
        }
    }

    /**
     * 设置沉寖式样式
     */
    public void setBasicUI() {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
            Window window = getWindow();
            window.addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
        } else {
        }
        StatusBarDarkModeUtils.setMeizuStatusBarDarkIcon(this, true);
        StatusBarDarkModeUtils.setMiuiStatusBarDarkMode(this, true);
    }
}
